sysroot: Split out a helper function to delete a deployment dir
authorColin Walters <walters@verbum.org>
Wed, 11 Apr 2018 17:30:32 +0000 (13:30 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 11 Apr 2018 19:11:07 +0000 (19:11 +0000)
Prep for staged deployments.

Closes: #1535
Approved by: jlebon

src/libostree/ostree-sysroot-cleanup.c
src/libostree/ostree-sysroot-private.h

index 2e7cd44bb8017be1be5c753debf0b65e68934135..1d46222b9a572e788107edde682925db19072838 100644 (file)
@@ -239,6 +239,44 @@ cleanup_other_bootversions (OstreeSysroot       *self,
   return TRUE;
 }
 
+/* Delete a deployment directory */
+gboolean
+_ostree_sysroot_rmrf_deployment (OstreeSysroot *self,
+                                 OstreeDeployment *deployment,
+                                 GCancellable  *cancellable,
+                                 GError       **error)
+{
+  g_autofree char *origin_relpath = ostree_deployment_get_origin_relpath (deployment);
+  g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
+  struct stat stbuf;
+  glnx_autofd int deployment_fd = -1;
+
+  if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE,
+                       &deployment_fd, error))
+    return FALSE;
+
+  if (!glnx_fstat (deployment_fd, &stbuf, error))
+    return FALSE;
+
+  /* This shouldn't happen, because higher levels should
+   * disallow having the booted deployment not in the active
+   * deployment list, but let's be extra safe. */
+  if (stbuf.st_dev == self->root_device &&
+      stbuf.st_ino == self->root_inode)
+    return TRUE;
+
+  /* This deployment wasn't referenced, so delete it */
+  if (!_ostree_linuxfs_fd_alter_immutable_flag (deployment_fd, FALSE,
+                                                cancellable, error))
+    return FALSE;
+  if (!glnx_shutil_rm_rf_at (self->sysroot_fd, origin_relpath, cancellable, error))
+    return FALSE;
+  if (!glnx_shutil_rm_rf_at (self->sysroot_fd, deployment_path, cancellable, error))
+    return FALSE;
+
+  return TRUE;
+}
+
 /* As the bootloader configuration changes, we will have leftover deployments
  * on disk.  This function deletes all deployments which aren't actively
  * referenced.
@@ -279,36 +317,12 @@ cleanup_old_deployments (OstreeSysroot       *self,
     {
       OstreeDeployment *deployment = all_deployment_dirs->pdata[i];
       g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
-      g_autofree char *origin_relpath = ostree_deployment_get_origin_relpath (deployment);
-
-      if (!g_hash_table_lookup (active_deployment_dirs, deployment_path))
-        {
-          struct stat stbuf;
-          glnx_autofd int deployment_fd = -1;
 
-          if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE,
-                               &deployment_fd, error))
-            return FALSE;
-
-          if (!glnx_fstat (deployment_fd, &stbuf, error))
-            return FALSE;
-
-          /* This shouldn't happen, because higher levels should
-           * disallow having the booted deployment not in the active
-           * deployment list, but let's be extra safe. */
-          if (stbuf.st_dev == root_stbuf.st_dev &&
-              stbuf.st_ino == root_stbuf.st_ino)
-            continue;
+      if (g_hash_table_lookup (active_deployment_dirs, deployment_path))
+        continue;
 
-          /* This deployment wasn't referenced, so delete it */
-          if (!_ostree_linuxfs_fd_alter_immutable_flag (deployment_fd, FALSE,
-                                                        cancellable, error))
-            return FALSE;
-          if (!glnx_shutil_rm_rf_at (self->sysroot_fd, origin_relpath, cancellable, error))
-            return FALSE;
-          if (!glnx_shutil_rm_rf_at (self->sysroot_fd, deployment_path, cancellable, error))
-            return FALSE;
-        }
+      if (!_ostree_sysroot_rmrf_deployment (self, deployment, cancellable, error))
+        return FALSE;
     }
 
   /* Clean up boot directories */
index b2776e8da1a2411771ecc12fc650e83a4ba1436a..01b370e8a26cc96b2fa16105ac50ecd20007de70 100644 (file)
@@ -112,6 +112,12 @@ _ostree_sysroot_get_origin_relpath (GFile         *path,
                                     GCancellable  *cancellable,
                                     GError       **error);
 
+gboolean
+_ostree_sysroot_rmrf_deployment (OstreeSysroot *sysroot,
+                                 OstreeDeployment *deployment,
+                                 GCancellable  *cancellable,
+                                 GError       **error);
+
 char *_ostree_sysroot_join_lines (GPtrArray  *lines);
 
 gboolean _ostree_sysroot_query_bootloader (OstreeSysroot     *sysroot,